package android.chatApp;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.chatApp.R;
import android.chatApp.entity.Contact;
import android.chatApp.list.adapter.ExpandableContactListAdapter;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.Toast;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupClickListener;

public class ViewContactListActivity extends Activity implements OnChildClickListener,OnGroupClickListener{

	private ExpandableContactListAdapter adapter;
	private String FRIENDS = "Friends";
	private String FAMILY = "Family";
	private String COLLEAGUE = "Colleagues";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.viewcontactlist);
		ExpandableListView contactListView = (ExpandableListView) this.findViewById(R.id.contactListView);
		contactListView.setOnChildClickListener(this);
		contactListView.setOnGroupClickListener(this);
		this.adapter = new ExpandableContactListAdapter(this, getGroups(), getChildren());
		contactListView.setAdapter(adapter);
	}
	
	protected List<String> getGroups() {
		List<String> groups = new ArrayList<String>();
		groups.add(FRIENDS);
		groups.add(FAMILY);
		//groups.add(COLLEAGUE);
		return groups;
	}
	
	protected List<ArrayList<Contact>> getChildren() {
		
		List<ArrayList<Contact>> children = new ArrayList<ArrayList<Contact>>();
		
		ArrayList<Contact> friendList= new ArrayList<Contact>();
		Contact friend1 = new Contact(FRIENDS, "Nguyen Chi Hai", "shareheart_4u");
		Contact friend2 = new Contact(FRIENDS, "To Xuan Triet", "txtriet");
		friendList.add(friend1);
		friendList.add(friend2);
		
		ArrayList<Contact> familyList = new ArrayList<Contact>();
		Contact sister = new Contact(FAMILY, "Pham Ngoc Nha", "ngocnha_ir");
		familyList.add(sister);
		
		children.add(friendList);
		children.add(familyList);
		return children;
	}

	@Override
	public boolean onChildClick(ExpandableListView parent, View v,
			int groupPosition, int childPosition, long id) {
		// TODO Auto-generated method stub
		Contact contact = (Contact) this.adapter.getChild(groupPosition, childPosition);
        Toast.makeText(getBaseContext(), "Child clicked + name = " + contact.getName() + "  id = " + contact.getId(), Toast.LENGTH_LONG).show();
        return false;
	}

	@Override
	public boolean onGroupClick(ExpandableListView parent, View v,
			int groupPosition, long id) {
		// TODO Auto-generated method stub
		Toast.makeText(getBaseContext(), "Group clicked", Toast.LENGTH_SHORT).show();
        return false;
	}
}
